package com.whales.lms.rms.scheduler.task;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import anyframe.common.util.StringUtil;

import com.whales.lms.rms.scheduler.TaskTemplate;
import com.whales.lms.rms.web.model.PcItemVO;
import com.whales.lms.rms.web.service.PcItemService;
import com.whales.lms.rms.web.util.ConstantUtil;
import com.whales.shared.util.PjlinkApp;

@Component
public class ProjectorLifeTimeUpdateTask extends TaskTemplate {
	@Inject
	private PcItemService pcItemService;
	
	public ProjectorLifeTimeUpdateTask() {
		this.setConExpression("0 01 * * * ?"); //매일 01시 동작
	}
	
	@Override
	public void execute() throws Exception {
		for(PcItemVO pcItemVO : pcItemService.findProjector()){
			if(StringUtil.isNotEmpty(pcItemVO.getIp())){
				PjlinkApp pjlinkApp = new PjlinkApp();
				pjlinkApp.pjlinkSetting(pcItemVO.getIp(), ConstantUtil.PROJECTOR_PORT, "");
				String lampHour = pjlinkApp.projectorHours();
				//lamp time update
				if(StringUtil.isNotEmpty(lampHour) && StringUtil.isNumeric(lampHour)){
					PcItemVO updateVo = new PcItemVO();
					updateVo.setId(pcItemVO.getId());
					updateVo.setLifeTime(Integer.parseInt(lampHour));
					pcItemService.updateProjectorLifeTime(updateVo);
				}else{
					System.out.println(lampHour + " is not numberic");
				}
			}
		}
	}
}
